home *** CD-ROM | disk | FTP | other *** search
/ Aminet 50 / Aminet 50 (2002)(GTI - Schatztruhe)[!][Aug 2002].iso / Aminet / text / misc / wvware-mos.lha / bin / wvDVI < prev    next >
Text File  |  2002-05-07  |  7KB  |  304 lines

  1. #!/bin/sh
  2.  
  3. wv_script_name="$0"
  4.  
  5. which latex >/dev/null 2>&1
  6. if [ ${?} -ne "0" ]; then
  7.   echo "Could not find required program 'latex'"
  8.   exit 1
  9. fi
  10.  
  11. prefix=/gg
  12. exec_prefix=
  13. datadir=
  14. t_dir=.
  15.  
  16. wv_opts=
  17. i_file=
  18. o_file=
  19. print_help=no
  20.  
  21. while test $# -gt 0; do
  22.   case "$1" in
  23.   -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
  24.   *) optarg= ;;
  25.   esac
  26.  
  27.   case $1 in
  28.     --prefix=*)
  29.       prefix=$optarg
  30.       ;;
  31.     --exec-prefix=*)
  32.       exec_prefix=$optarg
  33.       ;;
  34.     --datadir=*)
  35.       datadir=$optarg
  36.       ;;
  37.     --targetdir=*)
  38.       t_dir=$optarg
  39.       ;;
  40.     --charset=* | --password=*)
  41.       wv_opts="$wv_opts $1"
  42.       ;;
  43.     -v | --version)
  44.       echo 0.7.2
  45.       exit 0
  46.       ;;
  47.     -\? | -h | --help)
  48.       cat << EOF
  49. Usage: $wv_script_name [OPTIONS] <input-file> <output-file>
  50. Options:
  51.       --prefix=<DIR>        Set prefix (default is /gg)
  52.       --exec-prefix=<DIR>   Set exec_prefix (default is ${prefix})
  53.       --datadir=<DIR>       Set datadir (default is ${prefix}/share)
  54.       --targetdir=<DIR>     Target directory (target is <DIR>/<output-file>)
  55.       --charset=<charset>   Specify an iconv charset encoding
  56.       --password=<password> Specify password for encrypted
  57.   -v, --version             Print version info and exit
  58.  
  59. Authors:
  60.   Dom Lachowicz (dominicl@seas.upenn.edu)
  61.   Caolan McNamara (original author)
  62. Visit http://www.wvware.com/
  63. EOF
  64.       exit 0
  65.       ;;
  66.     -?*)
  67.       echo "Option '$1' not recognized."
  68.       exit 1
  69.       ;;
  70.     *)
  71.       if test "x$i_file" = "x"; then
  72.         i_file=$1
  73.       elif test "x$o_file" = "x"; then
  74.         o_file=$1
  75.       else
  76.         echo "Option '$1' not recognized."
  77.         exit 1
  78.       fi
  79.       ;;
  80.   esac
  81.   shift
  82. done
  83.  
  84. if test "x$i_file" = "x-"; then
  85.   echo "error: cannot specify '-' as input"
  86.   exit 1
  87. fi
  88. if test -r "$i_file"; then
  89.   okay=yes
  90. else
  91.   echo "error: '$i_file' unreadable"
  92.   exit 1
  93. fi
  94.  
  95. if test "x$o_file" = "x"; then
  96.   echo "Usage: $1 [OPTIONS] <input-file> <output-file>"
  97.   exit 1
  98. fi
  99. if test "x$i_file" = "x-"; then
  100.   echo "error: cannot specify '-' as output"
  101.   exit 1
  102. fi
  103. name=`basename "$o_file"`
  104. if test "x$o_file" != "x$name"; then
  105.   echo "error: use '--targetdir' for writing in another directory"
  106.   exit 1
  107. fi
  108. name=`basename "$o_file" | sed "s/ /_/g"`
  109. name=`echo $name | sed 's/\.[^\.]*$//'`
  110.  
  111. if test "x$exec_prefix" = "x"; then
  112.   exec_prefix=${prefix}
  113. fi
  114. wv_exec="$exec_prefix/bin/wvWare"
  115. if test -x "$wv_exec"; then
  116.   okay=yes
  117. else
  118.   wv_version=`wvWare -v 2>&1 | cut -f 2 -d " "`
  119.   if test "x$wv_version" = "x0.7.2"; then
  120.     wv_exec="wvWare"
  121.   else
  122.     echo "error: no executable at '$wv_exec' or in path"
  123.     exit 1
  124.   fi
  125. fi
  126.  
  127. if test "x$datadir" = "x"; then
  128.   datadir=${prefix}/share
  129. fi
  130. xmlcfg="$datadir/wv/wvLaTeX.xml"
  131. if test -r "$xmlcfg"; then
  132.   okay=yes
  133. else
  134.   echo "error: '$xmlcfg' unreadable"
  135.   exit 1
  136. fi
  137.  
  138. if test -d "$t_dir"; then
  139.   if test -w "$t_dir"; then
  140.     okay=yes
  141.   else
  142.     echo "error: '$t_dir' is not writable"
  143.     exit 1
  144.   fi
  145. else
  146.   echo "error: '$t_dir' is not a directory"
  147.   exit 1
  148. fi
  149.  
  150. # auto_wmf=`"$wv_exec" --auto-eps=wmf`
  151. # auto_emf=`"$wv_exec" --auto-eps=emf`
  152. # auto_png=`"$wv_exec" --auto-eps=png`
  153. # auto_jpg=`"$wv_exec" --auto-eps=jpg`
  154. # auto_pict=`"$wv_exec" --auto-eps=pict`
  155.  
  156. im_chk=`convert --help 2>&1 | grep -v ImageMagick`
  157. if test "x$im_chk" = "x"; then
  158.   im_chk="no"
  159.   s_img=""
  160. else
  161.   im_chk="yes"
  162. # if we have ImageMagick's convert, then use that to convert PNG, JPEG & PICT
  163. # to EPS. Therefore, need to suppress wvWare's desire to convert these:
  164.   s_img="png,jpg,pict"
  165. fi
  166.  
  167. "$wv_exec" $wv_opts -x "$xmlcfg" -d "$t_dir" -b "$name" "$i_file" -s "$s_img" > "$t_dir"/"$name".tex
  168.  
  169. cd "$t_dir"
  170.  
  171. echo
  172. echo 'Current directory: '`pwd`
  173.  
  174. # First, convert any images
  175.  
  176. i_okay=yes
  177.  
  178. for i_name in "$name"*.wmf; do
  179.   if test -r "$i_name"; then
  180.     e_name=`echo "$i_name" | sed 's/wmf$/eps/'`
  181.     if test -r "$e_name"; then
  182.       echo '"'$e_name'"' exists - skipping...
  183.     else
  184.       if test "$im_chk" = "yes"; then
  185.         convert "$i_name" "$e_name"
  186.         if test -r "$e_name"; then
  187.           echo created '"'$e_name'"'
  188.         else
  189.           echo '"'$i_name'"': conversion failed
  190.           i_okay=no
  191.         fi
  192.       else
  193.         echo unable to convert '"'$i_name'"' '(no converter)'
  194.         i_okay=no
  195.       fi
  196.     fi
  197.   fi
  198. done
  199.  
  200. for i_name in "$name"*.emf; do
  201.   if test -r "$i_name"; then
  202.     e_name=`echo "$i_name" | sed 's/emf$/eps/'`
  203.     if test -r "$e_name"; then
  204.       echo '"'$e_name'"' exists - skipping...
  205.     else
  206.       echo unable to convert '"'$i_name'"' '(no converter)'
  207.       i_okay=no
  208.     fi
  209.   fi
  210. done
  211.  
  212. for i_name in "$name"*.png; do
  213.   if test -r "$i_name"; then
  214.     e_name=`echo "$i_name" | sed 's/png$/eps/'`
  215.     if test -r "$e_name"; then
  216.       echo '"'$e_name'"' exists - skipping...
  217.     else
  218.       if test "$im_chk" = "yes"; then
  219.         convert "$i_name" "$e_name"
  220.         if test -r "$e_name"; then
  221.           echo created '"'$e_name'"'
  222.         else
  223.           echo '"'$i_name'"': conversion failed
  224.           i_okay=no
  225.         fi
  226.       else
  227.         echo unable to convert '"'$i_name'"' '(no converter)'
  228.         i_okay=no
  229.       fi
  230.     fi
  231.   fi
  232. done
  233.  
  234. for i_name in "$name"*.jpg; do
  235.   if test -r "$i_name"; then
  236.     e_name=`echo "$i_name" | sed 's/jpg$/eps/'`
  237.     if test -r "$e_name"; then
  238.       echo '"'$e_name'"' exists - skipping...
  239.     else
  240.       if test "$im_chk" = "yes"; then
  241.         convert "$i_name" "$e_name"
  242.         if test -r "$e_name"; then
  243.           echo created '"'$e_name'"'
  244.         else
  245.           echo '"'$i_name'"': conversion failed
  246.           i_okay=no
  247.         fi
  248.       else
  249.         echo unable to convert '"'$i_name'"' '(no converter)'
  250.         i_okay=no
  251.       fi
  252.     fi
  253.   fi
  254. done
  255.  
  256. for i_name in "$name"*.pict; do
  257.   if test -r "$i_name"; then
  258.     e_name=`echo "$i_name" | sed 's/pict$/eps/'`
  259.     if test -r "$e_name"; then
  260.       echo '"'$e_name'"' exists - skipping...
  261.     else
  262.       if test "$im_chk" = "yes"; then
  263.         convert "$i_name" "$e_name"
  264.         if test -r "$e_name"; then
  265.           echo created '"'$e_name'"'
  266.         else
  267.           echo '"'$i_name'"': conversion failed
  268.           i_okay=no
  269.         fi
  270.       else
  271.         echo unable to convert '"'$i_name'"' '(no converter)'
  272.         i_okay=no
  273.       fi
  274.     fi
  275.   fi
  276. done
  277.  
  278. if test "$i_okay" = "no"; then
  279.   echo 'WARNING: Failed to convert one or more images to EPS'
  280. fi
  281.  
  282. # "$name".tex is the LaTeX file
  283. # use latex to convert this to DVI
  284.  
  285. latex --interaction=batchmode "$name".tex >/dev/null 2>&1
  286.  
  287. # check latex exit status and comment or clean up
  288. if [ ${?} -ne "0" ]; then
  289.     echo "Some problem running latex."
  290.     echo "Check for Errors in $name.log"
  291.     echo "Continuing..."
  292. else
  293.     rm -f "$name".aux "$name".log "$name".tex
  294. fi
  295.  
  296. # latex replaces the "tex" extension with a "dvi" extension
  297. if [ ! -f "$name".dvi ]; then
  298.     echo "Conversion into dvi failed"
  299.     exit 1
  300. fi
  301.  
  302. cp -f "$name".dvi "$o_file"
  303. rm -f "$name".dvi
  304.